package com.example.demo.aspect;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
@Slf4j
@Aspect
@Component
public class AspectDemo1 {    //切面类

    @Pointcut("execution(* com.example.demo.controller.*.*(..))")   //切点
    public void pt(){};

    @Around("execution(* com.example.demo.controller.*.*(..))")   //  .*所有的类   .*所有的方法
    public Object timeRecord(ProceedingJoinPoint pjp)  {
        log.info("目标方法执行前...");

        Object proceed= null;
        try {
            proceed = pjp.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        log.info("目标方法执行后.....");

        return proceed;
    }

    @Before("execution(* com.example.demo.controller.*.*(..))")     //在写的时候,括号里的内容重复过多,可以提取出来,引出切点概念
    public void Before(){
        log.info("doBefore...");
    }
    @After("pt()")       //切面
    public void After(){
        log.info("doAfter...");
    }
    @AfterReturning("pt()")   //切面
    public void doAfterReturning(){
        log.info("doAfterReturning....");
    }

    @AfterThrowing("pt")
    public void doAfterThrowing(){
        log.info("doAfterThrowing....");
    }
}
